function sum(arr, n) {
  // Only change code below this line
  if (n <= 0) {
    return 0;
  } else if (n === 1) {
    return arr[0];
  } else {
    let result = sum(arr, n - 1) + arr[n - 1];
    console.log("result", result);
    return result;
  }
  // Only change code above this line
}

sum([2, 3, 4, 5], 3);

function countup(n) {
  if (n < 1) {
    return [];
  } else {
    const countArray = countup(n - 1);
    countArray.push(n);
    return countArray;
  }
}
console.log(countup(5)); // [ 1, 2, 3, 4, 5 ]
